/** @ingroup vtparser
 * @file vtparser.h
 * @brief vtparser 
 *
 * an implementation of [Paul Williams' DEC compatible state machine
 * parser](http://www.vt100.net/emu/dec_ansi_parser) written by Joshua Haberman
 *
 * @author Joshua Haberman <joshua@reverberate.org>
 * @author _modified by_ cameris <camerisdump@gmail.com>
 */

#ifndef PARSER_H_
#define PARSER_H_

#include "vtparser_table.h"
#include <stdint.h>

#define MAX_INTERMEDIATE_CHARS 2 /**< @brief maximal recognized intermediate characters */
#define ACTION(state_change) (state_change & 0x0F) /**< @brief get action from state_change */
#define STATE(state_change)  (state_change >> 4) /**< @brief get state from state_change */

struct vtparse;

/** @brief parser struct */
struct vtparse {
    enum vtparse_state state;
	void (*cb)(struct vtparse *parser, uint8_t action, uint8_t ch);
    int8_t ignore_flagged;
    uint8_t intermediate_chars[MAX_INTERMEDIATE_CHARS+1];
    uint8_t params[16];
    uint8_t num_params;
};

void vtparse_init(struct vtparse *parser,
		void (*cb)(struct vtparse *parser, uint8_t action , uint8_t ch));
void vtparse(struct vtparse *parser, uint8_t ch);
#endif
